import { createSlice } from '@reduxjs/toolkit'
import undoable from 'redux-undo' // 导入 undoable

const counterSlice = createSlice({
  // slice的名字
  name: 'counter',
  // 定义初始状态
  initialState: {
    value: 0,
    name: 'lisi'
  },
  // 定义 reducers 并生成关联的操作
  reducers: {
    increment: state => {
      state.value += 1
    },
    decrement: state => {
      state.value -= 1
    },
    incrementByAmount: (state, action) => {
      state.value += action.payload
    }
  }
})

export const { increment, decrement, incrementByAmount } = counterSlice.actions

// export default counterSlice.reducer

export default undoable(counterSlice.reducer, {
  limit: 20, // 限制历史记录最多 20 步
})
